<template>
  <div class="upload">
    <el-card>
      <h3 style="text-align: center">{{ $route.query.name }}导入</h3>
      <UploadExecl :on-success="onsuccess" />
    </el-card>
  </div>
</template>

<script>
import { sysUserBatch } from '@/api/employees.js'
export default {
  name: '',
  data() {
    return {}
  },
  computed: {},
  created() {},
  methods: {
    async onsuccess({ header, results }) {
      const obj = {
        入职时间: 'timeOfEntry',
        姓名: 'username',
        工号: 'workNumber',
        手机号: 'mobile',
        转正日期: 'correctionTime'
      }
      const arr = results.map((item) => {
        const newObj = {}
        Object.keys(item).forEach((item2) => {
          newObj[obj[item2]] = item[item2]
          if (obj[item2] === 'timeOfEntry' || obj[item2] === 'correctionTime') {
            // newObj[obj[item2]] = this.changeTime(item[item2])
          }
        })
        return newObj
      })
      await sysUserBatch(arr)
      this.$message.success('导入成功')
      this.$router.push('/employees')
      console.log(header, results, arr)
    },
    // 将excel时间（1990）转换成标准时间（1970）
    changeTime(num) {
      const t = new Date((num - 1) * (24 - 8) * 60 * 60 * 1000)
      t.setYear(t.getFullYear() - 70)
    }
  }
}
</script>
<style lang="less" scoped></style>
